package com.sixtwo.member.controller;

import com.alibaba.fastjson.JSON;
import com.sixtwo.dto.CommonResult;
import com.sixtwo.member.dto.MemberDto;
import com.sixtwo.member.feign.MemberFeign;
import com.sixtwo.member.service.MemberService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 会员信息查询
 *
 * @author zhengsh
 * @date 20210-07-06
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    private Logger logger = LoggerFactory.getLogger(MemberController.class);

    @Autowired
    private MemberFeign memberFeign;
    @Autowired
    private MemberService memberService;

    /**
     * 查询账户信息
     *
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public CommonResult<MemberDto> get(@PathVariable Long id) {
        CommonResult<MemberDto> result = memberFeign.revokeAccount(id);
        logger.info("memberFeign.revokeAccount result : {}", JSON.toJSONString(result));
        return CommonResult.success(new MemberDto());
    }

    /**
     * 注册
     *
     * @param memberDto
     * @return
     */
    @PostMapping("/register")
    public CommonResult<MemberDto> register(@RequestBody MemberDto memberDto) {
        Long id = memberService.insert(memberDto);
        memberDto.setId(id);
        return CommonResult.success(memberDto);
    }

    /**
     * 销户
     *
     * @param id
     * @return
     */
    @GetMapping("/revokeAccount/{id}")
    public CommonResult<MemberDto> revokeAccount(@PathVariable("id") Long id) {

        return CommonResult.success(new MemberDto());
    }

    /**
     * 退出登录
     *
     * @param id
     * @return
     */
    @GetMapping("/logout/{id}")
    public CommonResult<MemberDto> logout(@PathVariable Long id) {
        return CommonResult.success(new MemberDto());
    }

    /**
     * 登录
     *
     * @param memberDto
     * @return
     */
    @PostMapping("/login")
    public CommonResult<MemberDto> login(@RequestBody MemberDto memberDto) {
        return CommonResult.success(new MemberDto());
    }
}
